﻿@model YodaMaster.Models.Schedule
@using  System.Data;

@{
    ViewBag.Title = "Schedule_Courses_backward";
}

<p></p>
<p></p>
<h2>Schedule Courses</h2>

@Html.ActionLink("Schedule Courses","Schedule_Courses_forward", "ScheduleController", null)



@Html.ActionLink("Previous Schedule","Schedule_Courses_backward", "ScheduleController", null)



        @Html.ActionLink("Save Schedule", "SaveSchedule");
    


  

@Html.ActionLink("View Tests","View_Tests", "ScheduleController", null)


<h3> Schedule number @Model.numofschedule </h3>
      @if(Model.Type==YodaMaster.Models.Schedule.Schedule_Type.Valid)
      {
          <h3></h3>
      }
      else
      {
           <h3> Schedule has overlaps  </h3>
        }

<table border="1"> 
    <thead> 
    <tr> 
    @foreach (System.Data.DataColumn col in Model.table.timetable.Columns)     
    {          
        <th>@col.ColumnName</th> 
    }     
    </tr> 
    </thead>         
    <tbody> 

       

           @foreach (System.Data.DataRow row in Model.table.timetable.Rows)     
          {
            foreach (DataColumn col in Model.table.timetable.Columns)
           {
               int i = Model.table.timetable.Rows.IndexOf(row);
               if (i > 0 && Model.table.timetable.Rows[i - 1][col].ToString().Contains(row[col.ColumnName].ToString()) == true && row[col.ColumnName].ToString() != "" && Model.table.timetable.Rows[i - 1][col].ToString().Contains("@") == false)
               {
                   row[col.ColumnName] = row[col.ColumnName] + "%$";
               }
           }
        }
          
    
      


    @foreach (System.Data.DataRow row in Model.table.timetable.Rows)     
    {
        
        
        <tr> 
        @foreach (DataColumn col in Model.table.timetable.Columns)         
        {
            
            if(row[col.ColumnName].ToString().Contains("%$"))
            {
                row[col.ColumnName] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"";    
            }
            if(row[col.ColumnName].ToString().Contains("@"))
            {
                <td style =" background-color: #FF0000"> @Html.Raw(row[col.ColumnName].ToString().Replace(Environment.NewLine, "<br />"))   </td>
            }
           else if(row[col.ColumnName].ToString().IsEmpty() || col.ColumnName == "Hour/Day")
           {
                 <td> @Html.Raw(row[col.ColumnName].ToString().Replace(Environment.NewLine, "<br />"))   </td> 
           } 
           else
           {
               <td style =" background-color:#00FF00"> @Html.Raw(row[col.ColumnName].ToString().Replace(Environment.NewLine, "<br />"))   </td> 
           }  
            
        }         
        </tr> 
    }     
    </tbody> 
</table>